﻿using System;
using System.Collections;
using System.Collections.Generic;
using Nomo.UnityCoreModule.Enumerators;
using UnityEngine;

namespace Nomo.UnityCoreModule
{
    /// <summary>
    /// 提供用于控制协程执行流程的枚举器。
    /// </summary>
    public static class Wait
    {
        /// <seealso cref="WaitForEndOfFrame"/>
        public static WaitForEndOfFrame ForEndOfFrame { get; } = new WaitForEndOfFrame();

        /// <summary>
        /// 等待，直到下一次 MonoBehaviour.Update 执行完毕。
        /// </summary>
        public static IEnumerator Null { get; } = null;

        /// <seealso cref="WaitForFixedUpdate"/>
        public static WaitForFixedUpdate ForFixedUpdate { get; } = new WaitForFixedUpdate();

        /// <seealso cref="WaitForSeconds"/>
        public static WaitForSeconds ForSeconds(float seconds)
        {
            return new WaitForSeconds(seconds);
        }

        /// <seealso cref="WaitForSecondsRealtime"/>
        public static WaitForSecondsRealtime ForSecondsRealtime(float time)
        {
            return new WaitForSecondsRealtime(time);
        }

        /// <seealso cref="WaitUntil"/>
        public static WaitUntil Until(Func<bool> predicate)
        {
            return new WaitUntil(predicate);
        }

        /// <seealso cref="WaitWhile"/>
        public static WaitWhile While(Func<bool> predicate)
        {
            return new WaitWhile(predicate);
        }

        /// <seealso cref="WaitDuring"/>
        public static WaitDuring During(float seconds, Action<float> action)
        {
            return new WaitDuring(seconds, action);
        }

        /// <seealso cref="WaitDuringRealtime"/>
        public static WaitDuringRealtime DuringRealtime(float time, Action<float> action)
        {
            return new WaitDuringRealtime(time, action);
        }

        /// <seealso cref="WaitAny"/>
        public static WaitAny Any(IEnumerable<Func<bool>> predicates)
        {
            return new WaitAny(predicates);
        }
    }
}
